package com.neu.wms.service;
import com.neu.wms.dto.PersmissionDto;
import com.neu.wms.mapper.SysMenuMapper;
import com.neu.wms.vo.TreeNodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author DAIJUNQIANG
 * @version 1.0
 * @description TODO
 * @date 2023/7/8 19:33
 */
@Service
public class PermissionServiceImpl  implements  PermissionService{


	@Autowired
	private SysMenuMapper menuMapper;

	@Override
	@Transactional
	public void updatePermissionByRid(PersmissionDto persmissionDto) {
		menuMapper.deletePermissionByRid(persmissionDto.getRoleId());
		menuMapper.insertPermissionByRoleID(persmissionDto);
	}

	@Override
	public Integer[] selectByRid(Integer rid) {
		return menuMapper.selectByRid(rid);
	}

	@Override
	public List<TreeNodeVo> selectAll(Integer parentId) {
		List<TreeNodeVo> treeNodeVos = menuMapper.selectAll(parentId);
		if (treeNodeVos != null) {
			for (TreeNodeVo nodeVo : treeNodeVos) {
				List<TreeNodeVo> treeNodeVos1 = selectAll(nodeVo.getId());
				nodeVo.setChildren(treeNodeVos1);
			}
		}
		return treeNodeVos;
	}
}
